package com.jingdun.sport.common.util;


import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import jodd.util.StringUtil;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Minutes;
import org.joda.time.Seconds;
import org.springframework.util.StringUtils;

public class DateUtil {
    private static final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
    public static String FORMAT_SHORT = "yyyy-MM-dd";
    public static String FORMAT_LONG = "yyyy-MM-dd HH:mm:ss";
    public static String FORMAT_FULL = "yyyy-MM-dd HH:mm:ss.S";
    public static String FORMAT_SHORT_CN = "yyyy年MM月dd日";
    public static String FORMAT_LONG_CN = "yyyy年MM月dd日  HH时mm分ss秒";
    public static String FORMAT_FULL_CN = "yyyy年MM月dd日  HH时mm分ss秒SSS毫秒";
    public static String FORMAT_INT_MINITE = "yyyyMMddHHmmss";
    public static String FORMAT_INT_DATE = "yyyyMMdd";

    public DateUtil() {
    }

    public static String format(Date date) {
        return format(date, FORMAT_LONG);
    }

    public static Date parse(String date) {
        return DateUtil.parseDate(date);
    }

    public static String format(Date date, String pattern) {
        String returnValue = "";
        if (date != null) {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            returnValue = df.format(date);
        }

        return returnValue;
    }

    public static String fromDateH() {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format1.format(new Date());
    }

    public static String fromDateH2() {
        DateFormat format1 = new SimpleDateFormat("yyyyMMddHHmmss");
        return format1.format(new Date());
    }

    public static String fromCurrentDate() {
        DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        return format1.format(new Date());
    }

    public static String getCurrentMillisecond() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return sdf.format(new Date());
    }

    public static String fromDateY() {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        return format1.format(new Date());
    }

    public static String fromDateY2() {
        DateFormat format1 = new SimpleDateFormat("yyyyMMdd");
        return format1.format(new Date());
    }

    public static String getDateStringH(Date date) {
        return getDateString(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String getDateStringH2(Date date) {
        return getDateString(date, "yyyy/MM/dd HH:mm:ss");
    }

    public static String getDateStringY(Date date) {
        return getDateString(date, "yyyy-MM-dd");
    }

    public static String getDateString(Date date, String format) {
        if (date != null) {
            SimpleDateFormat formatter = new SimpleDateFormat(format);
            String dateString = formatter.format(date);
            return dateString;
        } else {
            return null;
        }
    }

    public static Timestamp getTimestamp(String time) {
        return Timestamp.valueOf(time);
    }

    public static Timestamp getTimestamp(Date date) {
        return new Timestamp(date.getTime());
    }

    public static String getOrderNum() {
        Date date = new Date();
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        Random random = new Random();
        String rand = String.valueOf(random.nextInt(100000));

        for (int j = 0; j < 5 - rand.length(); ++j) {
            rand = rand + "0";
        }

        return df.format(date) + rand;
    }

    public static String getYyyyMMddHHmmss() {
        Date date = new Date();
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        return df.format(date);
    }

    public static String getFormatDate(Timestamp timestamp) {
        Date date = new Date(timestamp.getTime());
        String pattern = "yyyy-MM-dd";
        return getFormatDate(pattern, date);
    }

    public static String getFormatDateTime(Timestamp timestamp) {
        Date date = new Date(timestamp.getTime());
        String pattern = "yyyy-MM-dd HH:mm:ss";
        return getFormatDate(pattern, date);
    }

    public static String getFormatDate(String pattern, Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(date);
    }

    public static String getFormatDate(String date) {
        return StringUtil.isNotEmpty(date) ? date.substring(0, 10) : null;
    }

    public static String getCurrentDate(String pattern) {
        if (pattern == null || pattern.trim().equals("")) {
            pattern = "yyyy-MM-dd HH:mm:ss";
        }

        pattern = pattern.trim();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(new Date());
    }

    public static String getCurrentDate() {
        return getCurrentDate("yyyy-MM-dd");
    }

    public static Timestamp getRollTime(Timestamp timestamp, int calendarField, int rollAmount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(timestamp.getTime()));
        cal.add(calendarField, rollAmount);
        return new Timestamp(cal.getTimeInMillis());
    }

    public static Timestamp getRollYear(Timestamp timestamp, int rollAmount) {
        return getRollTime(timestamp, 1, rollAmount);
    }

    public static Timestamp getRollMonth(Timestamp timestamp, int rollAmount) {
        return getRollTime(timestamp, 2, rollAmount);
    }

    public static Timestamp getRollDay(Timestamp timestamp, int rollAmount) {
        return getRollTime(timestamp, 7, rollAmount);
    }

    public static int getIntervalDays(Timestamp bigTime, Timestamp littleTime) {
        String t1str = getTimestampStr(bigTime);
        String t2str = getTimestampStr(littleTime);
        Timestamp t1 = getTimestampFormat(t1str);
        Timestamp t2 = getTimestampFormat(t2str);
        long intervalTime = t1.getTime() - t2.getTime();
        int intervalDay = (int) (intervalTime / 1000L / 60L / 60L / 24L);
        return intervalDay;
    }

    public static int getIntervalRefundMonths(Timestamp bigTime, Timestamp littleTime) {
        return getIntervalChargeMonths(bigTime, littleTime);
    }

    public static int getIntervalChargeMonths(Date bigTime, Date littleTime) {
        Calendar bigCalendar = Calendar.getInstance();
        bigCalendar.setTime(new Date(bigTime.getTime()));
        Calendar littleCalendar = Calendar.getInstance();
        littleCalendar.setTime(new Date(littleTime.getTime()));
        int intervalYear = getIntervalYears(bigTime, littleTime);
        int intervalMonth = bigCalendar.get(2) - littleCalendar.get(2);
        int n = intervalYear * 12 + intervalMonth;
        n = n < 0 ? 0 : n;
        return n;
    }

    public static int getIntervalYears(Date bigTime, Date littleTime) {
        Calendar bigCalendar = Calendar.getInstance();
        bigCalendar.setTime(new Date(bigTime.getTime()));
        Calendar littleCalendar = Calendar.getInstance();
        littleCalendar.setTime(new Date(littleTime.getTime()));
        return bigCalendar.get(1) - littleCalendar.get(1);
    }

    public static String getTimestampStr(Timestamp timestamp) {
        String pattern = "yyyy-MM-dd";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(new Date(timestamp.getTime()));
    }

    public static boolean compareDate(Timestamp t1, Timestamp t2) {
        String d1 = getFormatDate(t1);
        String d2 = getFormatDate(t2);
        return d1.compareTo(d2) > 0;
    }

    public static boolean compareDateTime(Timestamp t1, Timestamp t2) {
        String d1 = getFormatDateTime(t1);
        String d2 = getFormatDateTime(t2);
        return d1.compareTo(d2) > 0;
    }

    public static boolean compareDate(Date d1, Date d2) {
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(d1);
        c2.setTime(d2);
        return c1.compareTo(c2) > 0;
    }

    public static Timestamp getTimestampFormat(String dateStr) {
        String year = dateStr.substring(0, 4);
        String month = dateStr.substring(5, 7);
        if (month.startsWith("0")) {
            month = month.substring(1);
        }

        String day = dateStr.substring(8, 10);
        if (day.startsWith("0")) {
            day = day.substring(1);
        }

        Calendar cal = Calendar.getInstance();
        cal.set(1, Integer.parseInt(year));
        cal.set(2, Integer.parseInt(month) - 1);
        cal.set(5, Integer.parseInt(day));
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        return new Timestamp(cal.getTimeInMillis());
    }

    public static boolean equalDate(Timestamp t1, Timestamp t2) {
        String d1 = getFormatDate(t1);
        String d2 = getFormatDate(t2);
        return d1.equals(d2);
    }

    public static String getFormatedTimestampStr(Timestamp timestamp, String pattern) {
        if (pattern == null || "".equals(pattern)) {
            pattern = "yyyy-MM-dd kk:mm";
        }

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(new Date(timestamp.getTime()));
    }

    public static Timestamp getMonthLastDay(String year, String month) {
        Calendar cal = Calendar.getInstance();
        cal.set(1, Integer.parseInt(year));
        cal.set(2, Integer.parseInt(month) - 1);
        cal.set(5, 1);
        cal.add(2, 1);
        cal.add(5, -1);
        return Timestamp.valueOf(year + "-" + month + "-" + cal.get(5) + " 23:59:59");
    }

    public static Date parseDate(String str) {
        try {
            return df.parse(str);
        } catch (ParseException var2) {
            var2.printStackTrace();
            throw new RuntimeException(var2);
        }
    }

    public static Date parseDateyyyyMMdd(String str) {
        try {
            return df2.parse(str);
        } catch (ParseException var2) {
            var2.printStackTrace();
            throw new RuntimeException(var2);
        }
    }

    public static String formatDateTime(Date d) {
        return d == null ? null : df.format(d);
    }

    public static String formatDateTime(Date d, SimpleDateFormat format) {
        return format.format(d);
    }

    public static String formatDate(Date d) {
        return df2.format(d);
    }

    public static int getMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(2);
    }

    public static int getDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(5);
    }

    public static String getIntervalSecond(Date t1, Date t2) {
        long d = t2.getTime() - t1.getTime();
        return d + "";
    }

    public static long getIntervalTime(Date t1, Date t2) {
        long d = t2.getTime() - t1.getTime();
        return d;
    }

    public static Date getNextDayYYYYMMdd(Date date) {
        date = rollDay(date, 1);
        return getDateYYYYMMdd(dateStr2(date));
    }

    public static Date getNextDayYYYYMMddByDay(Date date, int day) {
        date = rollDay(date, day);
        return getDateYYYYMMdd(dateStr2(date));
    }

    public static Date getNextDayYYYYMMddByMonth(Date date, int mon) {
        date = rollMon(date, mon);
        return getDateYYYYMMdd(dateStr2(date));
    }

    public static Date getNextDayYYYYMMddHHMMSSByMonth(Date date, int mon) {
        date = rollMon(date, mon);
        return getDateYYYYMMddHHMMSS(dateStr3(date));
    }

    public static Date rollDay(Date d, int day) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        cal.add(5, day);
        return cal.getTime();
    }

    public static String dateStryyyyMMdd(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String str = format.format(date);
        return str;
    }

    public static String dateStr2(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = format.format(date);
        return str;
    }

    public static String dateStr3(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = format.format(date);
        return str;
    }

    public static Date getDateYYYYMMdd(String str) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;

        try {
            date = format.parse(str);
        } catch (ParseException var4) {
            var4.printStackTrace();
        }

        return date;
    }

    public static Date getDateYMD(String str) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = null;

        try {
            date = format.parse(str);
        } catch (ParseException var4) {
            var4.printStackTrace();
        }

        return date;
    }

    public static Date rollMon(Date d, int mon) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        cal.add(2, mon);
        return cal.getTime();
    }

    public static Date getDateYYYYMMddHHMMSS(String str) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;

        try {
            date = format.parse(str);
        } catch (ParseException var4) {
            var4.printStackTrace();
        }

        return date;
    }

    public static String getDistanceTime(Date one, Date two) throws ParseException {
        long day = 0L;
        long hour = 0L;
        long min = 0L;
        long sec = 0L;
        long time1 = one.getTime();
        long time2 = two.getTime();
        long diff;
        if (time1 < time2) {
            diff = time2 - time1;
        } else {
            diff = time1 - time2;
        }

        day = diff / 86400000L;
        hour = diff / 3600000L - day * 24L;
        min = diff / 60000L - day * 24L * 60L - hour * 60L;
        sec = diff / 1000L - day * 24L * 60L * 60L - hour * 60L * 60L - min * 60L;
        return day + "天" + hour + "小时" + min + "分" + sec + "秒";
    }

    public static String getMonday(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.set(5, 1);
        return getDateStringY(cal.getTime());
    }

    public static String getEarlierMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.set(5, 1);
        return getDateStringY(cal.getTime());
    }

    public static String getYearOne(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.set(6, 1);
        return getDateStringY(cal.getTime());
    }

    public static Date getZeroSecondDate(Date date) {
        String str = getDateStringH(date);
        str = str.substring(0, str.length() - 3) + ":00";
        return parseDate(str);
    }

    public static Date getZeroSecondDate(String str) {
        return getZeroSecondDate(parseDate(str));
    }

    public static void main(String[] args) {
        System.out.print(getNextDateBySpecify(new Date("2017-07-06"), 1));
    }

    public static String fromNowStartTime() {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        return format1.format(new Date()) + " 00:00:00";
    }

    public static String fromNowEndTime() {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        return format1.format(new Date()) + " 23:59:59";
    }

    public static Date formEndTime(Date d) {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        return getDateYYYYMMddHHMMSS(format1.format(d) + " 23:59:59");
    }

    public static Date formStartTime(Date d) {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        return getDateYYYYMMddHHMMSS(format1.format(d) + " 00:00:00");
    }

    public static Date getMonthLastDay(Date date) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        ca.set(5, ca.getActualMaximum(5));
        return ca.getTime();
    }

    public static Date getMonthFirstDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(2, 0);
        c.set(5, 1);
        return c.getTime();
    }

    public static int daysBetween(Date smdate, Date bdate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        try {
            smdate = sdf.parse(sdf.format(smdate));
            bdate = sdf.parse(sdf.format(bdate));
        } catch (ParseException var10) {
            return 0;
        }

        Calendar cal = Calendar.getInstance();
        cal.setTime(smdate);
        long time1 = cal.getTimeInMillis();
        cal.setTime(bdate);
        long time2 = cal.getTimeInMillis();
        long between_days = (time2 - time1) / 86400000L;
        return Integer.parseInt(String.valueOf(between_days));
    }

    public static int getLastDayOfMonth(Date sDate) {
        Calendar cDay = Calendar.getInstance();
        cDay.setTime(sDate);
        int lastDay = cDay.getActualMaximum(5);
        return lastDay;
    }

    public static String getTitel(Date date, String titel) {
        if (date != null && titel != null) {
            DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
            if ("2015-11-11".equals(format1.format(date)) && titel.indexOf("【双十一】") < 0) {
                return "【双十一】" + titel;
            }
        }

        return titel;
    }

    public static String DateMonthChange(Date d, int i) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(d);
        rightNow.add(2, i);
        Date dt1 = rightNow.getTime();
        String reStr = sdf.format(dt1);
        return reStr;
    }

    public static String DateDayChange(String date) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dt = sdf.parse(date);
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(6, 1);
        Date dt1 = rightNow.getTime();
        String reStr = sdf.format(dt1);
        return reStr;
    }

    public static String getDatePattern() {
        return FORMAT_LONG;
    }

    public static Date getCurrent() {
        Calendar c = Calendar.getInstance();
        return c.getTime();
    }

    public static String getNow() {
        return format(new Date());
    }

    public static String getNow(String format) {
        return format(new Date(), format);
    }

    public static Date parse(String strDate, String pattern) {
        SimpleDateFormat df = new SimpleDateFormat(pattern);

        try {
            return df.parse(strDate);
        } catch (ParseException var4) {
            var4.printStackTrace();
            return null;
        }
    }

    public static Date addMonth(Date date, int n) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(2, n);
        return cal.getTime();
    }

    public static Date addDay(Date date, int n) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(5, n);
        return cal.getTime();
    }

    public static String getTimeString() {
        SimpleDateFormat df = new SimpleDateFormat(FORMAT_FULL);
        Calendar calendar = Calendar.getInstance();
        return df.format(calendar.getTime());
    }

    public static String getYear(Date date) {
        return format(date).substring(0, 4);
    }

    public static int countDays(String date) {
        long t = Calendar.getInstance().getTime().getTime();
        Calendar c = Calendar.getInstance();
        c.setTime(parse(date));
        long t1 = c.getTime().getTime();
        return (int) (t / 1000L - t1 / 1000L) / 3600 / 24;
    }

    public static int countDays(String date, String format) {
        long t = Calendar.getInstance().getTime().getTime();
        Calendar c = Calendar.getInstance();
        c.setTime(parse(date, format));
        long t1 = c.getTime().getTime();
        return t > t1 ? (int) (t / 1000L - t1 / 1000L) / 3600 / 24 : (int) (t1 / 1000L - t / 1000L) / 3600 / 24;
    }

    public static Date getDayBegin(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        return calendar.getTime();
    }

    public static Date getDayEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        date = getDayBegin(date);
        calendar.setTime(date);
        calendar.add(5, 1);
        calendar.add(13, -1);
        return calendar.getTime();
    }

    public static Date getDifferentTime(int day, int hour, int minute, int second) {
        GregorianCalendar calendar = (GregorianCalendar) Calendar.getInstance();
        calendar.add(5, day);
        calendar.add(10, hour);
        calendar.add(12, minute);
        calendar.add(13, second);
        return calendar.getTime();
    }

    public static String fillGap(int num, int figure) {
        NumberFormat formatter = NumberFormat.getNumberInstance();
        formatter.setMinimumIntegerDigits(figure);
        formatter.setGroupingUsed(false);
        return formatter.format((long) num);
    }

    public static int getMinutesBetween(Date beginDate, Date endDate) {
        return null != beginDate && null != endDate ? Minutes.minutesBetween(new DateTime(beginDate), new DateTime(endDate)).getMinutes() : 0;
    }

    public static int getSecondsBetween(Date beginDate, Date endDate) {
        return null != beginDate && null != endDate ? Seconds.secondsBetween(new DateTime(beginDate), new DateTime(endDate)).getSeconds() : 0;
    }

    public static long getMillSecondsBetween(DateTime beginDate, DateTime endDate) {
        return null != beginDate && null != endDate ? beginDate.getMillis() - endDate.getMillis() : 0L;
    }

    public static boolean isSameDay(Date sourceDate, Date targetDate) {
        return Days.daysBetween(new DateTime(sourceDate), new DateTime(targetDate)).getDays() == 0;
    }

    public static boolean isCurrentDay(Date date) {
        return Days.daysBetween(DateTime.now(), new DateTime(date)).getDays() == 0;
    }

    public static long getMillis(Date date) {
        return (new DateTime(date)).getMillis();
    }

    public static Date getNowTime() {
        return new Date();
    }

    public static String formatDateTime(String dateTime) {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;

        try {
            date = timeStrFormater.parse(dateTime);
        } catch (ParseException var5) {
            var5.printStackTrace();
        }

        SimpleDateFormat timeFormater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String datetime = timeFormater.format(date);
        return datetime;
    }

    public static String formatDateTime2(String dateTime) {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyMMddHHmmss");
        Date date = null;

        try {
            if (dateTime != null && dateTime.contains(".0")) {
                dateTime = dateTime.replace(".0", "");
            }

            date = timeStrFormater.parse(dateTime);
        } catch (ParseException var5) {
            var5.printStackTrace();
        }

        SimpleDateFormat timeFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String datetime = timeFormater.format(date);
        return datetime;
    }

    public static String formatDateTimeToStr(Date dateTime) {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = timeStrFormater.format(dateTime);
        return date;
    }

    public static String formatDateTimeToStrTime(Date dateTime) {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("HH:mm:ss");
        String date = timeStrFormater.format(dateTime);
        return date;
    }

    public static String formatDateTimeToStr2(Date dateTime) {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyMMddHHmmss");
        String date = timeStrFormater.format(dateTime);
        return date;
    }

    public static String formatDateToYearAndMonth(Date dateTime) {
        SimpleDateFormat timeFormater = new SimpleDateFormat("yyyy-MM");
        String returnDate = timeFormater.format(dateTime);
        return returnDate;
    }

    public static Date formatStrToDateTime(String dateTime) throws Exception {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = timeStrFormater.parse(dateTime);
        return date;
    }

    public static Date formatStrToDateTime2(String dateTime) throws Exception {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = timeStrFormater.parse(dateTime);
        return date;
    }

    public static Date formatStrToDateTime3(String dateTime) throws Exception {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyMMddHHmmss");
        Date date = timeStrFormater.parse(dateTime);
        return date;
    }

    public static Date formatStrToDate(String dateTime) {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;

        try {
            date = timeStrFormater.parse(dateTime);
        } catch (ParseException var4) {
            var4.printStackTrace();
        }

        return date;
    }

    public static Date formatMonthStrToDate(String dateTime) throws Exception {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyyy-MM");
        Date date = timeStrFormater.parse(dateTime);
        return date;
    }

    public static Date formatYearStrToDate(String dateTime) throws Exception {
        SimpleDateFormat timeStrFormater = new SimpleDateFormat("yyyy");
        Date date = timeStrFormater.parse(dateTime);
        return date;
    }

    public static int daysBetweens(Date smdate, Date bdate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        try {
            smdate = sdf.parse(sdf.format(smdate));
            bdate = sdf.parse(sdf.format(bdate));
            Calendar cal = Calendar.getInstance();
            cal.setTime(smdate);
            long time1 = cal.getTimeInMillis();
            cal.setTime(bdate);
            long time2 = cal.getTimeInMillis();
            long between_days = (time2 - time1) / 86400000L;
            return Integer.parseInt(String.valueOf(between_days));
        } catch (ParseException var10) {
            return 0;
        }
    }

    public static int daysBetween(String smdate, String bdate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(smdate));
        long time1 = cal.getTimeInMillis();
        cal.setTime(sdf.parse(bdate));
        long time2 = cal.getTimeInMillis();
        long between_days = (time2 - time1) / 86400000L;
        return Integer.parseInt(String.valueOf(between_days));
    }

    public static int weeksBetweenTwoDate(Date smdate, Date bdate, int week) throws ParseException {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = getDates(df.format(smdate), df.format(bdate), week);
        int size = list.size();
        return size;
    }

    public static int weeksBetweenTwoDate(Date smdate, Date bdate, int week, List<Map<String, String>> dateList) throws ParseException {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = getDates(df.format(smdate), df.format(bdate), week);
        int count = 0;
        Iterator var7 = list.iterator();

        while (var7.hasNext()) {
            String date = (String) var7.next();
            Iterator var9 = dateList.iterator();

            while (var9.hasNext()) {
                Map<String, String> tempMap = (Map) var9.next();
                String tempDate = (String) tempMap.get("UPDATE_TIME");
                if (date.equals(tempDate)) {
                    ++count;
                }
            }
        }

        return count;
    }

    public static int daysBetweenTwoDate(Date smdate, Date bdate, int day) throws ParseException {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = getDatesSpeDay(df.format(smdate), df.format(bdate), day);
        int size = list.size();
        return size;
    }

    public static int daysBetweenTwoDate(Date smdate, Date bdate, int day, List<Map<String, String>> dateList) throws ParseException {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = getDatesSpeDay(df.format(smdate), df.format(bdate), day);
        int count = 0;
        Iterator var7 = list.iterator();

        while (var7.hasNext()) {
            String date = (String) var7.next();
            Iterator var9 = dateList.iterator();

            while (var9.hasNext()) {
                Map<String, String> tempMap = (Map) var9.next();
                String tempDate = (String) tempMap.get("UPDATE_TIME");
                if (date.equals(tempDate)) {
                    ++count;
                }
            }
        }

        return count;
    }

    public static List<String> getDates(String dateFrom, String dateEnd, int weekDays) {
        long time = 1L;
        long perDayMilSec = 86400000L;
        List<String> dateList = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        try {
            dateFrom = sdf.format(sdf.parse(dateFrom).getTime() - perDayMilSec);

            while (true) {
                time = sdf.parse(dateFrom).getTime();
                time += perDayMilSec;
                Date date = new Date(time);
                dateFrom = sdf.format(date);
                if (dateFrom.compareTo(dateEnd) > 0) {
                    break;
                }

                Integer weekDay = dayForWeek(date);
                if (weekDay == weekDays) {
                    dateList.add(dateFrom);
                }
            }
        } catch (ParseException var11) {
            var11.printStackTrace();
        }

        return dateList;
    }

    public static Integer dayForWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(7);
    }

    public static Integer dayForMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(5);
    }

    public static Integer dayForYear(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(6);
    }

    public static Integer hourODay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(11);
    }

    public static List<String> getDatesSpeDay(String dateFrom, String dateEnd, int day) {
        long time = 1L;
        long perDayMilSec = 86400000L;
        List<String> dateList = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        try {
            dateFrom = sdf.format(sdf.parse(dateFrom).getTime() - perDayMilSec);

            while (true) {
                time = sdf.parse(dateFrom).getTime();
                time += perDayMilSec;
                Date date = new Date(time);
                dateFrom = sdf.format(date);
                if (dateFrom.compareTo(dateEnd) > 0) {
                    break;
                }

                Integer tempDay = dayForMonth(date);
                if (tempDay == day) {
                    dateList.add(dateFrom);
                }
            }
        } catch (ParseException var11) {
            var11.printStackTrace();
        }

        return dateList;
    }

    public static List<String> getDaysByMonth(String month) {
        List<String> dateList = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if (StringUtils.isEmpty(month)) {
            return dateList;
        } else {
            Calendar cal = Calendar.getInstance();
            cal.set(1, Integer.valueOf(month.substring(0, 4)));
            cal.set(2, Integer.valueOf(month.substring(5, 7)));
            cal.set(5, 1);
            cal.add(5, -1);
            Date lastDate = cal.getTime();
            cal.set(5, 1);
            Date firstDate = cal.getTime();
            dateList.add(sdf.format(firstDate));
            cal.add(5, 1);

            for (Date tempDate = cal.getTime(); tempDate.compareTo(lastDate) < 0; tempDate = cal.getTime()) {
                dateList.add(sdf.format(tempDate));
                cal.add(5, 1);
            }

            dateList.add(sdf.format(lastDate));
            return dateList;
        }
    }

    public static int getDaysForMonth(String statisticDate) throws Exception {
        Date date = new Date();
        if (!StringUtils.isEmpty(statisticDate)) {
            date = formatMonthStrToDate(statisticDate);
        }

        int year = date.getYear();
        int month = date.getMonth();
        Calendar cal = Calendar.getInstance();
        cal.set(1, year);
        cal.set(2, month);
        cal.set(5, 1);
        cal.roll(5, -1);
        int maxDate = cal.get(5);
        return maxDate;
    }

    public static List<String> getDaysBySpecificMonth(String statisticDate) throws Exception {
        List<String> dateList = new ArrayList();
        if (StringUtils.isEmpty(statisticDate)) {
            return dateList;
        } else {
            Date date = formatMonthStrToDate(statisticDate);
            int day;
            if (date.getMonth() == (new Date()).getMonth()) {
                day = (new Date()).getDate();
            } else {
                day = getDaysForMonth(statisticDate);
            }

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

            for (int i = 1; i <= day; ++i) {
                date.setDate(i);
                dateList.add(sdf.format(date));
            }

            return dateList;
        }
    }

    public static List<String> getMonthBetween(String minDate, String maxDate) throws ParseException {
        ArrayList<String> result = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(sdf.parse(minDate));
        min.set(min.get(1), min.get(2), 1);
        max.setTime(sdf.parse(maxDate));
        max.set(max.get(1), max.get(2), 2);
        Calendar curr = min;

        while (curr.before(max)) {
            result.add(sdf.format(curr.getTime()));
            curr.add(2, 1);
        }

        return result;
    }

    public static String[] toStringArray(List<String> strList) {
        String[] array = new String[strList.size()];
        strList.toArray(array);
        return array;
    }

    public static String removeFrontZero(String str) {
        String result = "";
        int len = 0;

        for (int i = 0; i < str.length(); ++i) {
            ++len;
            if (str.charAt(i) != '0') {
                break;
            }
        }

        if (len > 0) {
            result = str.substring(len - 1, str.length());
        }

        return result;
    }

    public static Date getNextDateBySpecify(Date date, Integer day) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(date.getTime());
        c.add(5, day);
        Date nextDate = new Date(c.getTimeInMillis());
        return nextDate;
    }

    public static Date getNextTimeBySpecify(Date date, long minute) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(date.getTime());
        Date nextDate = new Date(c.getTimeInMillis() + minute * 60L * 1000L);
        return nextDate;
    }

    public static Date getNextDateTimeBySpecify(Date date, long seconds) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(date.getTime());
        Date nextDate = new Date(c.getTimeInMillis() + seconds * 1000L);
        return nextDate;
    }

    public void dateDiff(String startTime, String endTime, String format) {
        SimpleDateFormat sd = new SimpleDateFormat(format);
        long nd = 86400000L;
        long nh = 3600000L;
        long nm = 60000L;
        long ns = 1000L;

        try {
            long diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
            long day = diff / nd;
            long hour = diff % nd / nh;
            long min = diff % nd % nh / nm;
            long sec = diff % nd % nh % nm / ns;
            System.out.println("时间相差：" + day + "天" + hour + "小时" + min + "分钟" + sec + "秒。");
        } catch (Exception var23) {
        }

    }

    public static Date getAfterYearDate(Date date, int num) {
        Calendar cal = Calendar.getInstance();
        if (date != null) {
            cal.setTime(date);
        }

        cal.add(1, num);
        return cal.getTime();
    }

    public static List<String> getYearBetween(Date startDate, Date endDate) {
        List<String> list = new ArrayList();
        Calendar calS = Calendar.getInstance();
        calS.setTime(startDate);
        Calendar calE = Calendar.getInstance();
        calE.setTime(endDate);
        int endYear = calE.get(1);

        for (int startYear = calS.get(1); startYear <= endYear; ++startYear) {
            list.add(String.valueOf(startYear));
        }

        return list;
    }

    public static String getWorkStartDate(String curDateStr, String workDateStr) throws ParseException {
        if (curDateStr != null && !"".equals(curDateStr) && workDateStr != null && !"".equals(workDateStr)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date curDate = sdf.parse(curDateStr);
            Date workDate = sdf.parse(workDateStr);
            return curDate != null && workDate != null && curDate.getTime() > workDate.getTime() ? curDateStr.substring(11, 19) : workDateStr.substring(11, 19);
        } else {
            return null;
        }
    }

    public static String getWorkEndDate(String curDateStr, String workDateStr) throws ParseException {
        if (curDateStr != null && !"".equals(curDateStr) && workDateStr != null && !"".equals(workDateStr)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date curDate = sdf.parse(curDateStr);
            Date workDate = sdf.parse(workDateStr);
            return curDate != null && workDate != null && curDate.getTime() < workDate.getTime() ? curDateStr.substring(11, 19) : workDateStr.substring(11, 19);
        } else {
            return null;
        }
    }

    public static double getHoursByStartAndEnd(String startDateStr, String endDateStr) throws ParseException {
        if (startDateStr != null && !"".equals(startDateStr) && endDateStr != null && !"".equals(endDateStr)) {
            SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            double between = 0.0D;
            Date begin = dfs.parse("1993-06-18 " + startDateStr);
            Date end = dfs.parse("1993-06-18 " + endDateStr);
            between = (double) (end.getTime() - begin.getTime());
            double hour = between / 3600000.0D;
            return hour;
        } else {
            return 0.0D;
        }
    }

    public static String getAfterMonthN(int month) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
        Calendar cal = Calendar.getInstance();
        cal.add(2, month);
        Date date = cal.getTime();
        return df.format(date);
    }

    public static Date getDate(String str) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;

        try {
            date = sdf.parse(str);
        } catch (ParseException var4) {
            var4.printStackTrace();
        }

        return date;
    }

    public static List<Date> findDates(Date dBegin, Date dEnd) {
        List lDate = new ArrayList();
        lDate.add(dBegin);
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(dEnd);

        while (dEnd.after(calBegin.getTime())) {
            calBegin.add(5, 1);
            lDate.add(calBegin.getTime());
        }

        return lDate;
    }
}
